<!--
 * @Author: cqg
 * @Date: 2021-04-22 14:56:17
 * @LastEditTime: 2021-04-22 16:20:09
 * @Description: 根据使用单位查询巡查不合格列表
 * @LastEditors: cqg
-->
<template>
  <div>
    <el-dialog title="巡查记录" width="1200px" :visible.sync="dialogVisible">
      <data-list
        v-if="dialogVisible"
        ref="dataList"
        searchName="propertyName"
        placeholder="请输入物业名称"
        :pageInfo="pager"
        :dataInfo="dataInfo"
        operaColumnWidth="120"
        :listData="patrolRecordList"
        :openIndex="true"
        :menuList="[]"
        :noPadding="true"
      />
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">关闭</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import {
  inspectionList
} from "@/views/wy-authorization/use-card/api/use-card.js";
import { getDict } from "~/utils";

export default {
  name: 'patrolDialog',
  provide () {
    return {
      initList: this.queryData
    };
  },
  data () {
    return {
      // 分页
      pager: {
        total: 0, // 总页数
        current: 1, // 当前页数
        size: 20 // 每页显示多少条
      },
      // 请求参数
      params: {
        current: 1,
        size: 20,
        useUnit: "",
        propertyName: ""
      },
      //巡查列表
      patrolRecordList: [],
      dialogVisible: false,

    }
  },

  computed: {
    // 表格展示字段
    dataInfo () {
      return [
        {
          label: "物业名称",
          prop: "propertyName"
        },
        {
          label: "地址",
          prop: "unitName"
          // "show-overflow-tooltip": true
        },
        { label: "使用单位名称", width: "150", prop: "useUnit" },
        {
          label: "所属管理所",
          prop: "manageUnit",
          formatter: this.dataFormatter
        },
        {
          label: "巡查日期",
          width: "150",

          prop: "inspectionDate"
        },
        {
          label: "巡查结果",
          prop: "inspectionResult",
          formatter: this.dataFormatter

        },
        {
          label: "备注说明",
          prop: "remarks"
        }
      ];
    },
  },
  methods: {
    show (params) {
      // 请求参数
      this.params = {
        current: 1,
        size: 20,
        useUnit: "",
        propertyName: ""
      },
        this.dialogVisible = true
      this.queryData(params);
    },
    async queryData (params = {}) {
      let requestData = { ...this.params, ...params };
      for (const key in requestData) {
        requestData[key] == "" && delete requestData[key];
      }
      let rps = await inspectionList(requestData);
      const { current, size, total, records } = rps.data.data;
      this.patrolRecordList = records;
      this.params = requestData;
      this.pager = { total, current, size };
    },
    dataFormatter (row, column, callValue) {
      let type = "";
      switch (column.property) {
        case "manageUnit":
          type = getDict("administrative_office").find(
            item => item.value == callValue
          );
          return type ? type.label : "";
        case "inspectionResult":
          type = getDict("inspection_result").find(
            item => item.value == callValue
          );
          return type ? type.label : "";
      }
    },
  },
}
</script>

<style lang="scss" scoped>
/deep/ .el-dialog__body {
  padding: 20px;
}
</style>
